import pygame

import globalvars


class DynPanelText(pygame.sprite.Sprite):
    """Dynamic panel text wich is only for use with strings that consists of numbers"""
    def __init__(self, var, dest):
        pygame.sprite.Sprite.__init__(self) # Initialize base class
        self.lastNumber = 0.0
        self.panelFont = pygame.font.SysFont("Arial", 20)
        self.Number = var
        self.update()

    def update(self):
        if self.lastNumber != self.Number:
            self.image = self.panelFont.render("%i" %(self.Number), True, [0, 0, 0])
            self.rect = self.image.get_rect()
            self.rect.topleft = [globalvars.resolution[0] - 15 - self.rect.width, 5]
            self.lastNumber = self.Number

